package com.huizhonglm.diap.core.utils;

import com.huizhonglm.diap.core.storage.db.DistrictDBUtil;
import com.huizhonglm.diap.core.storage.model.district.CityInfo;
import com.huizhonglm.diap.core.storage.model.district.DistInfo;
import com.huizhonglm.diap.core.storage.model.district.ProvInfo;
import com.huizhonglm.diap.model.District;

import java.util.List;

/**
 * 地区操作类
 *
 * @author LiXiaoLong
 * @version 1.0
 * @since 2015-02-09 11:23
 */
public class DistrictUtil {
    private DistrictDBUtil dbUtil;
    private static DistrictUtil mInstance;

    public static DistrictUtil getInstance() {
        if (mInstance == null) {
            synchronized (DistrictUtil.class) {
                if (mInstance == null) {
                    mInstance = new DistrictUtil();
                }
            }
        }
        return mInstance;
    }

    private DistrictUtil() {
        dbUtil = new DistrictDBUtil();
    }

    public List<ProvInfo> getProvData(){
        return dbUtil.getProvData();
    }

    public List<CityInfo> getCityDataByProvId(String provId, boolean hasAll) {
        List<CityInfo> data = dbUtil.getCityDataByProvId(provId);
        if (hasAll) {
            CityInfo info = new CityInfo();
            info.setCityId("9999999");
            info.setCityCode("009999");
            info.setProvId(provId);
            info.setCityName("全部");
            data.add(0, info);
        }
        return data;
    }

    public List<DistInfo> getDistDataByCityId(String cityId, boolean hasAll) {
        List<DistInfo> data = dbUtil.getDistDataByCityId(cityId);
        if (hasAll) {
            DistInfo info = new DistInfo();
            info.setDistId("9898989");
            info.setDistName("全城");
            info.setCityId(cityId);
            data.add(0, info);
        }
        return data;
    }

    public District getDistrict(String distId){
        return dbUtil.getDistrict(distId);
    }
}
